package vn.nt.healthcare.server.ws.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import vn.nt.healthcare.server.ws.model.Feedback;
import vn.nt.healthcare.server.ws.service.FeedbackService;

@Controller
public class FeedbackController {

	@Autowired
	private FeedbackService feedbackService;

	@RequestMapping(value = "/addfeedback", method = RequestMethod.POST)
	@ResponseBody
	public String addFeedback(HttpServletRequest request,
			HttpServletResponse response) {
		System.out.println("|====================>>  ");
		String companyId = request.getParameter("companyId");
		String customerId = request.getParameter("customerId");
		String comment = request.getParameter("comment");
		String goal = request.getParameter("goal");
		boolean result = feedbackService.save(companyId,
				Integer.parseInt(customerId), comment, Integer.parseInt(goal));
		if (result) {
			return "Thank you for feedback";
		} else {
			return "";
		}
	}

	@RequestMapping(value = "/listfeedbacks", method = RequestMethod.GET)
	@ResponseBody
	public List<Feedback> getListFeedbacks(HttpServletRequest request,
			@RequestParam(value = "companyId", required = true) String companyId) {
		return feedbackService.findAllFeedbacks(companyId);
	}
}
